//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <string.h>
#include <stdio.h>
#include <aura.h>

Aura_PWChar Pwchar_t_to_Aura_PWchar(
            /* [in] */  wchar_t* wszSrc,
            /* [out] */ Aura_PWChar desc)
{
    Aura_PWChar p = desc;
    if(desc == AURA_NULL){
        return desc;
    }
    if(wszSrc == AURA_NULL){
        desc[0]=0;
        return desc;
    }
    while (*wszSrc) {
        *desc++ = (Aura_WChar)*wszSrc++;
    }
    *desc = 0;
    return p;
}

EXTERN_C void AnsiToUnic(
            /* [out] */ Aura_PWChar desc,
            /* [in] */ char *src)
{
    while (*src) {
        *desc++ = (Aura_WChar)*src++;
    }
    *desc = 0;
}

void aurasystemtest()
{
    Aura_UInt32  uLoopCount;
    Aura_Int32   iTotleMem, iFreeMem;

    Aura_SystemTime sTime;
    Aura_Millisecond mTime;
    Aura_Int64 iTicks;

    AuraSystem_GetTime(&sTime);

    printf("System time seconds :%d\n", sTime.seconds);

    sTime.seconds += 30;

    if(AURA_FAILED(AuraSystem_SetTime(&sTime))){
        printf("Can not set time\n");
    }

    AuraSystem_GetTime(&sTime);

    printf("System Set time seconds :%d\n", sTime.seconds);

    printf("Wait 1000 Aura_Millisecond.\n");
    AuraThread_Sleep(1000, NULL);

    AuraSystem_GetElapsedTime(&mTime);

    printf("AuraSystem_GetElapsedTime:%d.\n", mTime);

    AuraSystem_GetTickCount(&iTicks);

    printf("AuraSystem_GetTickCount:%d.\n", iTicks);

    AuraSystem_GetLoopCountPerMicrosecond(&uLoopCount);

    printf("Aura System Get Loop Count Per Microsecond32:%d.\n", uLoopCount);

    AuraSystem_GetMemorySizes(&iTotleMem, &iFreeMem);

    printf("AuraSystem_GetMemorySizes: iTotleMem%d. iFreeMem:%d.\n", iTotleMem, iFreeMem);

    printf("END SYSTEM AND CRT TEST!\n");
}


void auracrttest()
{
    //TODO
    Aura_WChar wtmp[255];
    Aura_WChar wtmp1[255];
    AnsiToUnic(wtmp,"Aura_putws test: OK!");
    Aura_putws(wtmp);
    //Pwchar_t_to_Aura_PWchar(L"abcdabcd",wtmp);
    AnsiToUnic(wtmp,"SOK");
    Aura_printf("Aura_printf test s:%s\n", "OK!");
    Aura_printf("Aura_printf test S:%S\n", wtmp);
    Aura_printf("Aura_printf test d:%5d ok\n", 12);
    Aura_printf("Aura_printf test d:%5.6d ok\n", 12);
    Aura_printf("Aura_printf test d:%-0 5.6d ok\n", 12);

    Aura_WChar fullPath[AURA_MAX_DIR];
    AnsiToUnic(wtmp,"./bin");
    Aura_fullpath(fullPath, wtmp, AURA_MAX_DIR);
    AnsiToUnic(wtmp,"./bin fullPath is :%s.\n");
    Aura_swprintf(wtmp1,wtmp, fullPath);

    Aura_putws(wtmp1);
    AnsiToUnic(wtmp,"./bin fullPath is :%S.\n");
    Aura_swprintf(wtmp1,wtmp, "helloworld!");
    Aura_putws(wtmp1);

}

int main(int argc, char *argv[])
{
    auracrttest();

    aurasystemtest();

    return 0;
}

